<?php
/**
 * 舆情
 */
namespace app\model;

use think\Model;

class OpinionsModel extends Model
{
	protected $name = 'opinions';
	
	// 设置当前模型的数据库连接
	protected $connection ='db_yunduan';
   /**
    * 舆情列表
    *
    */
   public function GetList($where='1=1'){
    $OpinionsModel=new OpinionsModel;
    $result=$OpinionsModel->field('id,title,img,desc,url,froms,updatetime,status')->where($where)->order('id desc')->paginate()->toArray();
    foreach ($result['data'] as &$val){
    	$val['updatetime']=date('Y-m-d H:i:s',$val['updatetime']);
    }
    return $result;
   }
   /**
    * 舆情详情
    *
    */
   public function detail($id){
      $OpinionsModel = OpinionsModel::find($id);
      return $OpinionsModel;
   }
  /**
   * 添加
   *
  */
   public function AddData($param){
      $OpinionsModel = new OpinionsModel;
      $param['createtime']=time();
      $param['updatetime']=time();
      
      $field=['title','desc','img','url','froms','content','createtime','updatetime','role_id'];
      $OpinionsModel->allowField($field)->save($param);
      return $OpinionsModel->id; 
   }
  /**
   * 编辑
   *
  */
  public function EditData($param,$id){
   $OpinionsModel = OpinionsModel::find($id);
   $param['updatetime']=time();

   $field=['title','desc','img','url','froms','content','updatetime'];
  
   $OpinionsModel->allowField( $field)->save($param);
   return $id; 
  }
  /**
   * 修改禁用状态
   *
  */
  public function UpdateStatus($id){
   $OpinionsModel = OpinionsModel::find($id);
   $OpinionsModel->status=$OpinionsModel->status==1?0:1;
   $OpinionsModel->save();
   return true; 
  }
 /**
   * 删除
   *
  */
  public function Del($param){
   $update=[];
   foreach($param as $val){
       $update[]=['id'=>$val,'status'=>-1,'deletetime'=>time()];
   }
   if(!empty($update)){
      $OpinionsModel = new OpinionsModel;
      $OpinionsModel->saveAll($update);
   }
   return true; 
  }
}